<?php

namespace App\Admin\Actions\Post;

use App\Models\ProductAttrKey;
use App\Models\ProductAttrVal;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;

class DeleteAttrKey extends RowAction
{
    public $name = '删除';

    public function handle(Model $model)
    {
        $values = ProductAttrVal::where('key_id',$model->id)->first();
        if($values){
            return $this->response()->error('该属性名下有属性，暂不可删除！')->refresh();
        }

        ProductAttrKey::destroy($model->id);

        return $this->response()->success('Success message.')->refresh();
    }

    public function dialog()
    {
        $this->confirm('确定删除该属性吗？');
    }

}